//
//  Huati_guangchang_xiangqing_vc.m
//  ainkjj
//
//  Created by MAX on 2020/4/30.
//  Copyright © 2020 zhiyiLiu. All rights reserved.
//

#import "Huati_guangchang_xiangqing_vc.h"
#import "Huati_taolun_fabu_vc.h"
@interface Huati_guangchang_xiangqing_vc ()
@property (nonatomic, strong)NSMutableArray *titlesArr;
@property (nonatomic, strong)NSMutableArray *classNamesArr;
@property(nonatomic, strong) UIButton *normalButton;

@end

@implementation Huati_guangchang_xiangqing_vc
- (instancetype)init

{
    self = [super init];
    if (self) {
        self.progressWidth = 40;
        self.titleColorSelected = themeColor;
        self.titleColorNormal = UIColor.darkGrayColor;
        self.titleSizeNormal = 17;
        self.titleSizeSelected = 20;
        [self setMenuViewStyle:WMMenuViewStyleLine];
    }
    
    return self;
}
- (void)viewDidLoad{
    [super viewDidLoad];
    
        
    self.title = self.model.name;
//    self.model.topicNum = 11111;
//    self.model.showSum = 1111;
    NSString *topicNumStr = self.model.topicNum > 10000 ? [NSString stringWithFormat:@"%ldw", self.model.topicNum / 10000] : [NSString stringWithFormat:@"%ld", self.model.topicNum];
    
    NSString *showSumNumStr = self.model.showSum > 10000 ? [NSString stringWithFormat:@"%ldw", self.model.showSum / 10000] : [NSString stringWithFormat:@"%ld", self.model.showSum];

    
    self.titleView.subtitle = [NSString stringWithFormat:@"内容%@ 浏览%@", topicNumStr,  showSumNumStr];
    [self.titleView setStyle:QMUINavigationTitleViewStyleSubTitleVertical];
//    [self.titleView setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeading];
    

    
    
}

- (void)initSubviews{
    [super initSubviews];
    // 普通按钮
    UIButton *button = [[UIButton alloc] init];
    [self.view addSubview:button];
    self.normalButton = button;
    button.titleLabel.font = UIFontBoldMake(14);
    [button setTitleColor:UIColorWhite forState:UIControlStateNormal];
    //            button.backgroundColor = UIColor.qd_tintColor;
    [self.normalButton setTitle:@"立即参与话题" forState:UIControlStateNormal];
    [self.view addSubview:self.normalButton];
    self.normalButton.layer.cornerRadius = 44 * 0.5;
    self.normalButton.layer.masksToBounds = YES;
    [button addTarget:self action:@selector(canyu_action:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    
    
    // 普通按钮
    
    
    CGFloat btnWidth = ScreenWidth - 30 * 2;
    
    CGFloat originY = CGRectGetMaxY([self pageController:self preferredFrameForMenuView:self.menuView]);
    
    
    
    self.normalButton.frame = CGRectMake((self.view.bounds.size.width - btnWidth) * 0.5,  originY  +(self.view.bounds.size.height - originY - 68 - Lzy_TabbarSafeBottomMargin) + 15, btnWidth, 44);
    
    [self.normalButton setBackgroundImage:[Anktool gradient_img_create:rgb(255,107,149) toColor:rgb(255,163,191) frame:self.normalButton.frame] forState:UIControlStateNormal];
    
    
    
}
- (void)canyu_action:(UIButton *)sender{
    Huati_taolun_fabu_vc *vc= [[Huati_taolun_fabu_vc alloc]init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

- (NSMutableArray *)titlesArr{
    if(_titlesArr == nil)
    { _titlesArr = @[@"推荐", @"最新"].mutableCopy;
    }
    
    return _titlesArr;
}
- (NSMutableArray *)classNamesArr{
    if(_classNamesArr == nil)
    {_classNamesArr = @[ @"Huati_guangchang_xiangqing_tuijian_vc", @"Huati_guangchang_xiangqing_zuixin_vc"].mutableCopy;
    }
    
    return _classNamesArr;
}

#pragma mark - WMPageController DataSource
- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController {
    return self.titlesArr.count;
}

- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index {
    return self.titlesArr[index];
}

- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index {
    UIViewController *vc = nil;
    vc = [NSClassFromString(self.classNamesArr[index]) new];
    
    return vc;
}
-(CGRect)pageController:(WMPageController *)pageController preferredFrameForMenuView:(WMMenuView *)menuView{
    CGFloat originY =  CGRectGetMaxY(self.navigationController.navigationBar.frame);
    
    return  CGRectMake(0,  originY, [UIScreen mainScreen].bounds.size.width, 50);
}
- (CGRect)pageController:(WMPageController *)pageController preferredFrameForContentView:(WMScrollView *)contentView{
    CGFloat originY = CGRectGetMaxY([self pageController:pageController preferredFrameForMenuView:self.menuView]);
    
    return  CGRectMake(0,  originY, self.view.bounds.size.width,self.view.bounds.size.height - originY - 68 - Lzy_TabbarSafeBottomMargin);
    
}

@end
